<script setup>
import { ref, onMounted } from 'vue';
import { warnApi } from '@T2/service/api.ts';
import warnIcon from '~icons/custom/warn';

const warnList = ref([]);
onMounted(() => {
  getWarnList();
});
const getWarnList = () => {
  warnApi({
    method: 'get',
    params: {
      page: 1,
      pagesize: 4,
      ordering: '-create_time',
      reset_time__isnull: true,
      confirm_user__isnull: true,
    }
  }).then(res => {
    warnList.value = res?.results || [];
  });
}
const colorLevel = {
  '一': { color: '#0648D2', bgColor: '#DFEEFF' },
  '二': { color: '#FDA700', bgColor: '#FBF2DD' },
  '三': { color: '#F01D1D', bgColor: '#FFEDE9' },
  '四': { color: '#c01616', bgColor: '#efdedb' },
}
</script>

<template>
  <div class="warn-container flex flex-column">
    <div class="warn-item flex" v-for="item in warnList">
      <div class="icon-box flex-center-center" :style="{ backgroundColor: colorLevel[item.level]?.bgColor || '#DFEEFF' }">
        <warnIcon :color="colorLevel[item.level]?.color || '#0648D2'" />
      </div>
      <div class="warn-content flex-column">
        <label>{{ item.unit_name }} | {{ item.create_time }}</label>
        <p>{{ item.info }}</p>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.warn-container {
  width: 100%;
  height: 100%;
  padding: 12px 0;
  overflow: hidden;
}
.warn-item {
  padding: 6px 12px;
  &:hover {
    background-color: #F7FAFF;
  }
  .icon-box {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    margin-right: 16px;
  }
  .warn-content {
    flex: 1;
    overflow: hidden;
    label {
      font-weight: 400;
      font-size: 14px;
      color: #666666;
    }
    p {
      margin-top: 8px;
      font-weight: 400;
      font-size: 14px;
      color: #111111;
    }
  }
}
</style>